package com.ideapse.springcloud.client;

import com.ideapse.springcloud.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author LuoJianWei
 * @email LuoJianWei_98@foxmail.com
 * @date 2024/4/27 19:39
 */
@Service
public class DeptConsumerClient {

    @Autowired
    private RestTemplate restTemplate;

    private static final String URL_SUFFIX= "http://SPRINGCLOUD-PROVIDER-DEPT";

    public boolean addDept(Dept dept){
        return restTemplate.postForObject(URL_SUFFIX+"/dept/add",dept,Boolean.class);
    }

    public Dept getDeptById(Long id){
        return restTemplate.getForObject(URL_SUFFIX+"/dept/"+id,Dept.class);
    }

    public List<Dept> getAll(){
        return restTemplate.getForObject(URL_SUFFIX+"/dept/all",List.class);
    }
}
